package edu.usc.cmb.iregulome.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.usc.cmb.iregulome.dao.SampleStudyDAO;
import edu.usc.cmb.iregulome.entity.Study;

@Transactional
@Service("sampleStudyDAO")
public class SampleStudyDAOImpl implements SampleStudyDAO {
	
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public List<String> fetchStudyIds() {
		Session session = sessionFactory.getCurrentSession();
		Query q = session
				.createQuery("select s.id from Study s");
		return q.list();
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Override
	public List<Study> fetchALLStudies() {
		Session session = sessionFactory.getCurrentSession();
		Query q = session
				.createQuery("from Study s");
		return q.list();
	}

}
